home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / pcpil / sample4.pil < prev    next >
Text File  |  1979-12-31  |  4KB  |  85 lines

  1. T:Example of calling assembler
  2. T:language from a PILOT program.
  3. T:This is for assembler language 
  4. T:programmers only.
  5. T:
  6. R:
  7. R: The following is the X.LST file as created by the ASM program when the
  8. R: subroutine is assembled with the IBM assembler.
  9. R:
  10. R:                PROG     SEGMENT BYTE PUBLIC 'PROG'
  11. R:                TEST     PROC    FAR
  12. R:                         ASSUME  CS:PROG,DS:PROG
  13. R:                         ORG     0                   ;start at 0
  14. R:  0000  EB 0E            JMP     short GO            ;skip parm area
  15. R:                ; Above here should be exactly as shown.
  16. R:                ; Next, put in up to 125 bytes of parm area.
  17. R:  0002  41 42   PARM1:   DB      'AB'                ;parm from pilot prog
  18. R:  0004  43 44   PARM2:   DB      'CD'                ;parm to pilot prog
  19. R:  0006  45 46            DB      'EFGHIJKLMN'        ;filler (unused here)
  20. R:                ; here is the subroutine proper
  21. R:  0010  A1 0002 GO:      MOV     AX,PARM1            ;take input parm
  22. R:  0013  A3 0004          MOV     PARM2,AX            ;move it to output parm
  23. R:                ; below here shoud be exactly as shown
  24. R:  0016  CB               RET                         ;far return to pilot
  25. R:                TEST     ENDP
  26. R:                PROG     ENDS
  27. R:                         END
  28. R:
  29. R: If the above program were stored in file X.ASM then it could be prepared
  30. R: for use with PILOT as follows:
  31. R:      ASM X           (push return to 3 prompts from assembler)
  32. R:      LINK X          (push return to 3 prompts from linker)
  33. R:      EXE2BIN X
  34. R: The result is in file  X.BIN and could be loaded by a pilot program
  35. R: by the sequence     dx:a$(30)
  36. R:                     fx:X.BIN
  37. R:                     fi:0,a$
  38. R: Alternatively, the soubroutine could be built in the string by the pilot
  39. R: program as shown below.
  40. R:
  41. R:               next line creates string to hold the subroutine
  42. dx:a$(30)
  43. r:               next line puts in the JMP and fills the parm area with data
  44. c:a$=chr(235)!!chr(14)!!"abcdefghijklmn" 
  45. r:               next line fills in the rest of the subroutine
  46. c:a$=a$!!chr(161)!!chr(2)!!chr(01)!!chr(163)!!chr(4)!!chr(1)!!chr(203)
  47. r:               next lines insert the zeros because they can't be 
  48. r:               concatenated  the way PILOT handles strings.
  49. c:a$(22)=chr(0)
  50. c:a$(19)=chr(0)
  51. r:               next line shows the parm area to the user
  52. t:#(a$(3,14))
  53. T:
  54. T:Push return and watch what happens to
  55. T:the c and d in the above line.
  56. r:               next line waits for return key
  57. a:
  58. r:               next line calls the asm subr
  59. v:a$
  60. r:               next line shows user the changed parameter bytes
  61. t:#(a$(3,14))
  62. T:
  63. T:If you are interested in assembler
  64. T:lanugage subroutines, you can
  65. T:study this program to see how
  66. T:it can be done from PILOT.
  67. r:
  68. R:     the soubroutine could be saved on disk for use later via
  69. R:                 FX:XSUB
  70. R:                 FO:0,a$  
  71. R:     it could be read back in later by another program via
  72. R:                 DX:a$(30)
  73. R:                 FX:XSUB
  74. R:                 FI:0,a$
  75. R:     Notice that the subroutine assumes that both the code and data
  76. R:     segments start at the start of the program; thus it is assembled
  77. R:     for offset 0.  Also notice the technique of leaving some bytes
  78. R:     toward the start of the subroutine to allow for passing of data
  79. R:     to and from the subroutine. You could leave any number of bytes
  80. R:     in this manner. To pass data to the subroutine just set these bytes
  81. R:     by a statement like    C:a$(3,4)="EASY"       Then to get results
  82. R:     back from the subroutine have it store the result in the same
  83. R:     area and access it from the program via   C:x$=a$(3,4)
  84.  
  85.